# !/bin/zsh

rm -rf dist/

yarn build:prod

if [[ $? -eq 0 ]]; then
  echo -e "\033[32m Build Successful\033[0m"
else
  exit -1
fi

ssh ubuntu_server "cd /home/ubuntu/workspace/mpa-dance-server/ && rm -rf ./dist"

if [[ $? -eq 0 ]]; then
  echo -e "\033[32m Remove dist Successful\033[0m"
else
  exit -1
fi

scp -r ~/workspace/mpa-dance-server/dist ubuntu_server:/home/ubuntu/workspace/mpa-dance-server/dist

scp -r ~/workspace/mpa-dance-server/pm2.prod.json ubuntu_server:/home/ubuntu/workspace/mpa-dance-server/

scp -r ~/workspace/mpa-dance-server/src/message ubuntu_server:/home/ubuntu/workspace/mpa-dance-server/dist

if [[ $? -eq 0 ]]; then
  echo -e "\033[32m Scp Successful\033[0m"
else
  exit -1
fi

ssh ubuntu_server "cd /home/ubuntu/workspace/mpa-dance-server/ && pm2 reload mpa-dance-server"

if [[ $? -eq 0 ]]; then
  echo -e "\033[32m ssh pm2 reload Successful\033[0m"
else
  exit -1
fi

ssh ubuntu_server "pm2 l"
